<template>
    <div class="qingwu">
        <div class="admin_table_page_title">
            <a-button @click="$router.back()" class="float_right" icon="arrow-left">返回</a-button>
            代理商编辑
        </div>
        <div class="unline underm"></div>
        <div class="admin_form">
            <a-form-model :label-col="{ span: 5, offset: 1 }" :wrapper-col="{ span: 12}">
                <a-form-model-item label="代理商姓名">
                    <a-input v-model="info.agent_name"></a-input>
                </a-form-model-item>
                <a-form-model-item label="代理商手机号(作为后台登录账号)">
                    <a-input v-model="info.agent_mobile"></a-input>
                </a-form-model-item>
                <a-form-model-item label="商户号">
                    <a-input v-model="info.sub_mch_id"></a-input>
                </a-form-model-item>
                <a-form-model-item label="代理商身份证号">
                    <a-input v-model="info.agent_idcard"></a-input>
                </a-form-model-item>

                <a-form-model-item label="代理商类别">
                    <a-select v-model="info.agent_type" style="width: 120px">
                        <a-select-option value="disabled" disabled>
                            全部类别
                        </a-select-option>
                        <a-select-option :value="1">
                            个人
                        </a-select-option>
                        <a-select-option :value="2">
                            公司
                        </a-select-option>
                    </a-select>
                </a-form-model-item>

                <a-form-model-item label="代理商等级">
                    <a-select v-model="info.level" style="width: 120px" :options="list">
                    </a-select>
                </a-form-model-item>
                <a-form-model-item label="地区">
                    <a-cascader :options="options" :field-names="{ label: 'name', value: 'id', children: 'children' }"
                                placeholder="请选择地区" v-model="info.loadOptions"/>
                </a-form-model-item>
                <a-form-model-item label="详细地址">
                    <a-input v-model="info.detail"></a-input>
                </a-form-model-item>
                <a-form-model-item label="代理商备注">
                    <a-textarea v-model="info.agent_remarks"></a-textarea>
                </a-form-model-item>

                <a-form-model-item label="代理商备注">
                    <a-radio-group v-model="info.split_type">
                        <a-radio :value="1">
                            无
                        </a-radio>
                        <a-radio :value="2">
                            自动分账
                        </a-radio>
                        <a-radio :value="3">
                            人工分账
                        </a-radio>
                    </a-radio-group>
                </a-form-model-item>

                <div v-show="info.split_type == 2">
                    <a-form-model-item label="微信账户类型">
                        <a-select v-model="info.wechat_account_type_id" style="width: 250px">
                            <a-select-option v-for="item in type_options.wechat" v-bind:key="item.id" :value="item.id">
                                {{item.type_name}}-{{item.description}}
                            </a-select-option>
                        </a-select>
                    </a-form-model-item>
                    <a-form-model-item label="微信收款账户">
                        <a-input v-model="info.wechat_account"></a-input>
                    </a-form-model-item>

                    <a-form-model-item label="支付宝账户类型">
                        <a-select v-model="info.alipay_account_type_id" style="width: 250px">
                            <a-select-option v-for="item in type_options.alipay" v-bind:key="item.id" :value="item.id">
                                {{item.type_name}}-{{item.description}}
                            </a-select-option>
                        </a-select>
                    </a-form-model-item>
                    <a-form-model-item label="支付宝收款账户">
                        <a-input v-model="info.alipay_account"></a-input>
                    </a-form-model-item>
                    <a-form-model-item label="支付宝收款方全称">
                        <a-input v-model="info.alipay_name"></a-input>
                    </a-form-model-item>

                    <a-form-model-item label="分账比例">
                        <a-input v-model="info.rate" style="width: 100px;"></a-input>
                    </a-form-model-item>
                </div>

                <div v-show="info.split_type == 3">
                    <a-form-model-item label="开户行">
                        <a-select v-model="info.account_bank" style="width: 250px">
                            <a-select-option v-for="item in type_options.bank" v-bind:key="item.id" :value="item.bank_code">
                                {{item.bank_name}}
                            </a-select-option>
                        </a-select>
                    </a-form-model-item>
                    <a-form-model-item label="手续费比例">
                        <a-input v-model="info.else_discount" style="width: 100px;"></a-input>
                    </a-form-model-item>
                    <a-form-model-item label="收款人">
                        <a-input v-model="info.bank_user_name"></a-input>
                    </a-form-model-item>
                    <a-form-model-item label="银行卡号">
                        <a-input v-model="info.bank_card_number"></a-input>
                    </a-form-model-item>
                    <a-form-model-item label="分账比例">
                        <a-input v-model="info.rate2" style="width: 100px;"></a-input>
                    </a-form-model-item>
                </div>


                <a-form-model-item :wrapper-col="{ span: 12, offset: 5 }">
                    <a-button type="primary" @click="handleSubmit">提交</a-button>
                </a-form-model-item>
            </a-form-model>

        </div>
    </div>
</template>

<script>
    export default {
        components: {},
        props: {},
        data() {
            return {
                info: {},
                id: 0,
                list: [],
                options: [],
                type_options: {}
            };
        },
        watch: {},
        computed: {},
        methods: {
            handleSubmit() {
                let api = this.$apiHandle(this.$api.electricPlatformAgent, this.id);
                if (api.status) {
                    console.log(this.info);
                    this.$put(api.url, this.info).then(res => {
                        if (res.code == 200) {
                            this.$message.success(res.msg)
                            return this.$router.back();
                        } else {
                            return this.$message.error(res.msg)
                        }
                    })
                } else {
                    this.$post(api.url, this.info).then(res => {
                        if (res.code == 200) {
                            this.$message.success(res.msg)
                            return this.$router.back();
                        } else {
                            return this.$message.error(res.msg)
                        }
                    })
                }


            },
            get_info() {
                this.$get(this.$api.electricPlatformAgent + '/' + this.id).then(res => {
                    res.data.loadOptions = [Number(res.data.province), Number(res.data.city), Number(res.data.area)];
                    this.info = res.data;
                })
            },
            get_list() {
                this.$get(this.$api.region).then(res => {
                    this.options = res.data;
                })

                this.$get(this.$api.agentLevel).then(res => {
                    this.list = res.data;
                })

                this.$get(this.$api.electricOption).then(res => {
                    this.type_options = res.data;
                })
            },
            onload() {
                // 判断你是否是编辑
                if (!this.$isEmpty(this.$route.params.id)) {
                    this.id = this.$route.params.id;
                    this.get_info();
                }
                this.get_list();
            },


        },
        created() {
            this.onload();
        },
        mounted() {
        }
    };
</script>
<style lang="scss" scoped>

</style>
